package com.szosen.jkzj.activity.mbgy.plan;

import java.io.File;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.Call;
import okhttp3.Response;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.identity.MD5lib;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.request.BaseRequest;
import com.szosen.application.MyApplication;
import com.szosen.database.DBService;
import com.szosen.database.MedicineDesc;
import com.szosen.database.UploadRecord;
import com.szosen.database.Visit_info;
import com.szosen.database.base_info;
import com.szosen.database.xueya;
import com.szosen.device.jianhuyi.JianHuYiActivity;
import com.szosen.jkzj.R;
import com.szosen.jkzj.activity.BaseActivity;
import com.szosen.jkzj.activity.JKTJActivity2;
import com.szosen.jkzj.activity.OfflineUploadListActivity;
import com.szosen.jkzj.activity.UserListActivity;
import com.szosen.jkzj.activity.mbgy.Data;
import com.szosen.jkzj.activity.mbgy.PhotoRotateUtil;
import com.szosen.jkzj.activity.mbgy.Plan;
import com.szosen.jkzj.activity.mbgy.ShowDialog;
import com.szosen.json.JsonUtil;
import com.szosen.json.Root_Return;
import com.szosen.json.Visit;
import com.szosen.json.HypertensionMedicines;
import com.szosen.json.HypertensionVisit;
import com.szosen.util.BackGroundThread;
import com.szosen.util.FileSaveUtil;
import com.szosen.util.JktjBitmapUtil;
import com.szosen.util.SharedpreferenceUtil;
import com.szosen.util.StringUtils;
import com.szosen.util.TimeHelper;
import com.szosen.util.ToastTool;
import com.szosen.util.VisitContants;
import com.szosen.web.Fetch;
import com.szosen.web.ResultListener;
import com.szosen.web.WebService;
import com.szosen.xml.XmlTool;

/** 高血压 */
public class GXYPlan_Activity extends BaseActivity {

	// 更新界面标志
	private static final int FRESH_UI = 0x10;
	// 确认按钮
	private static final int POSITIVE = 0x11;
	// 保存成功
	private static final int SAVE_OK = 0x12;
	// 保存失败
	private static final int SAVE_ERROE = 0x13;

	private boolean lock = false;
	private Button editHelpBtn;
	private Button saveBtn;
	private View bodySv;
	private String time;

	EditText otherMedicineDesc1_et;
	EditText medicineFrequency1_et;
	EditText medicineDosage1_et;
	EditText otherMedicineDesc2_et;
	EditText medicineFrequency2_et;
	EditText medicineDosage2_et;
	EditText otherMedicineDesc3_et;
	EditText medicineFrequency3_et;
	EditText medicineDosage3_et;
	EditText otherMedicineDesc4_et;
	EditText medicineFrequency4_et;
	EditText medicineDosage4_et;
	String from = "";
	private EditText hypertension_edt_turedoctor;
	ImageView iv_mainImage;
	Data mData;
	Plan mPlan;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.hypertension_report);
		context = this;
		initView();
		from = getIntent().getStringExtra("flag");
		if (TextUtils.isEmpty(from)) {
			from = "";
		}
		String json = getIntent().getStringExtra("json");
		if (!TextUtils.isEmpty(json)) {
			System.out.println("获取的Jsondata" + json);
			mData = new Gson().fromJson(json, Data.class);
			String name = mData.getPersonName();
			String sex = TextUtils.isEmpty(mData.getSexCode()) ? "" : "1"
					.equals(mData.getSexCode()) ? "男" : "女";
			String phone = mData.getMobileNumber();
			String idcard = mData.getIdCard();
			List<Plan> plans = mData.getPlan();
			for (int i = 0; i < plans.size(); i++) {
				Plan p = plans.get(i);
				String type = p.getBusinessType();
				if ("1".equals(type)) {
					mPlan = p;
				}
			}
			setText(R.id.hypertension_turename, mData.getPersonName());
			String sfDate = TimeHelper.getJKTJCheckDate();
			setText(R.id.hypertension_reportdate, sfDate);
			hypertension_edt_turedoctor.setText(mData.getUid());
			setText(R.id.hypertension_turenum, mPlan.getRecordId());
		}

	}

	public void printTable(View view) {
		Visit_info visit_info = getupload();
		if (visit_info != null) {

			final List<Visit_info> lists = new ArrayList<Visit_info>();
			lists.add(visit_info);
			new BackGroundThread(new BackGroundThread.BackGroundTask() {
				@Override
				public void process() {
					JktjBitmapUtil.createGXYBitmap(context, lists);
				}
			}).start();
		} else {
			ToastTool.showShort(context, "打印错误，请检查填空！");
		}
	}

	public void jumpToMeasureBp(View view) {
		Intent intent = new Intent(GXYPlan_Activity.this, JianHuYiActivity.class);
		intent.putExtra("fromxueya", "xueya");
		intent.putExtra("from", 1);
		//血压测量的标记
		startActivityForResult(intent, JKTJActivity2.xueya_requestCode);
	}

	@Override
	@SuppressLint("ResourceAsColor")
	@SuppressWarnings("unchecked")
	protected void onResume() {
		super.onResume();
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		// setResult(HypertensionTure.REQUEST_FRESH);
	}

	@Override
	protected void onStart() {
		super.onStart();
		time = getIntent().getStringExtra("time");
		System.out.println("高血压获取的time" + time);
		if (TextUtils.isEmpty(time)) {
			if (!"new".equals(from)) {
				time = TimeHelper.getMainTimeKey();
				// 如果是新的记录。就从数据库获取最新的测量结果。
				base_info b = new base_info();
				b.setIdCard(mData.getIdCard());
				List<base_info> bs = (List<base_info>) DBService
						.queryByIdCard(b);
				if (bs != null && bs.size() > 0) {
					base_info bean = bs.get(bs.size() - 1);
					bean.getHeight();
					// 体重
					setText(R.id.hypertension_edt_weight, bean.getWeight());
					setText(R.id.hypertension_edt_index, bean.getBmi());
					// 心率
					setText(R.id.hypertension_edt_heartrate, bean.getPulse());
					// // 血压
					setText(R.id.hypertension_edt_bloodpresure,
							bean.getConstriction_L() + "/"
									+ bean.getDiastolic_L());
				}
				if ("new".equals(from)) {
					setText(R.id.hypertension_reportdate,
							TimeHelper.getJKTJCheckDate());
				}
			}
			return;
		} else {
			Visit_info queryBean = new Visit_info();
			queryBean.setTime(time);
			List<Object> lists = (List<Object>) DBService.queryByKey(queryBean);
			if (lists.size() > 0) {
				Visit_info visit_info = (Visit_info) lists.get(0);
				setDataToUI(visit_info);
			}
		}
	}

	protected void initView() {
		initYYQK();
		setChoiceEditText();
		iv_mainImage = (ImageView) findViewById(R.id.glycuresis_iv_mainImage);
		hypertension_edt_turedoctor = (EditText) findViewById(R.id.hypertension_edt_turedoctor);
		editHelpBtn = (Button) findViewById(R.id.hypertension_edit_helpbutton);
		saveBtn = (Button) findViewById(R.id.hypertension_title_btn);
		saveBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				upload();
			}
		});
		final EditText hypertension_druglist_et = (EditText) findViewById(R.id.hypertension_druglist);
		hypertension_druglist_et.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ShowDialog.show(GXYPlan_Activity.this,
						hypertension_druglist_et, ShowDialog.TYPE_HYP);
			}
		});
		bodySv = findViewById(R.id.hypertension_body);
		setText(R.id.hypertension_turename, BaseActivity.getHealthRecord()
				.getPersonName());
		final EditText hypertension_edt_bloodpresure = (EditText) findViewById(R.id.hypertension_edt_bloodpresure);
		hypertension_edt_bloodpresure
				.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						AlertDialog.Builder builder = new AlertDialog.Builder(
								GXYPlan_Activity.this);
						LayoutInflater inflater = (LayoutInflater) GXYPlan_Activity.this
								.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
						TableLayout tl = (TableLayout) inflater.inflate(
								R.layout.health_check_bloodpre, null);
						final EditText shuzhang = (EditText) tl
								.findViewById(R.id.et_shuzhang);
						final EditText shousuo = (EditText) tl
								.findViewById(R.id.et_shousuo);
						builder.setView(tl);
						builder.setTitle("填写您的血压");
						builder.setPositiveButton("确定",
								new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										hypertension_edt_bloodpresure
												.setText(shousuo.getText()
														+ "/"
														+ shuzhang.getText());
									}
								});
						builder.setNegativeButton("取消", null);
						builder.create().show();
					}
				});

	}

	private void initYYQK() {
		Activity tl = this;
		// ((TextView) tl.findViewById(R.id.yyqk_tv1)).setText("【胰岛素】种类：");
		// ((TextView) tl.findViewById(R.id.yyqk_tv2)).setText("用法：");
		// ((TextView) tl.findViewById(R.id.yyqk_tv3)).setText("用量：");
		// <otherMedicineDesc>药物名称</otherMedicineDesc>
		// <medicineFrequency>次数</medicineFrequency>
		// <days>天数</days>
		// <medicineDosage>每次剂量</medicineDosage>
		// <medicineUnit>剂量单位</medicineUnit>
		otherMedicineDesc1_et = (EditText) tl.findViewById(R.id.yyqk_DrugName1);
		medicineFrequency1_et = (EditText) tl.findViewById(R.id.yyqk_Usage1);
		medicineDosage1_et = (EditText) tl.findViewById(R.id.yyqk_Consumption1);
		otherMedicineDesc2_et = (EditText) tl.findViewById(R.id.yyqk_DrugName2);
		medicineFrequency2_et = (EditText) tl.findViewById(R.id.yyqk_Usage2);
		medicineDosage2_et = (EditText) tl.findViewById(R.id.yyqk_Consumption2);
		otherMedicineDesc3_et = (EditText) tl.findViewById(R.id.yyqk_DrugName3);
		medicineFrequency3_et = (EditText) tl.findViewById(R.id.yyqk_Usage3);
		medicineDosage3_et = (EditText) tl.findViewById(R.id.yyqk_Consumption3);
		otherMedicineDesc4_et = (EditText) tl
				.findViewById(R.id.yyqk_DrugNameOther);
		medicineFrequency4_et = (EditText) tl
				.findViewById(R.id.yyqk_UsageOther);
		medicineDosage4_et = (EditText) tl
				.findViewById(R.id.yyqk_ConsumptionOther);
		String datas = SharedpreferenceUtil.getYaowuDatas(tl, "",
				SharedpreferenceUtil.YAOWUDATAS_GXY);
		// String[] yaowus = datas.trim().split(
		// SharedpreferenceUtil.YAOWUDATAS_SPLIT);
		String[] yaowus = VisitContants.GXY.items;
		setChoiceEditText(R.id.yyqk_DrugName1, yaowus, null);
		setChoiceEditText(R.id.yyqk_DrugName2, yaowus, null);
		setChoiceEditText(R.id.yyqk_DrugName3, yaowus, null);
		setChoiceEditText(R.id.yyqk_DrugNameOther, yaowus, null);
	}

	// 拍照后相片的Uri
	private Uri imageUri;
	// 拍照后相片path
	private String imagePath;

	public void tackPhoto(View view) {
		/**
		 * 创建File对象，用于存储拍照后的图片 调用getExternalCacheDir方法可以得到应用关联目录
		 * /sdcard/Android/data/<package name>/cache 为何调用getExternalCacheDir？
		 * 因为Android从6.0开始。读写SD卡被认为是危险权限。如果将图片放在其他目录，需要动态申请权限 而使用关联目录可以跳过这一步
		 * */
		String userPath = FileSaveUtil.getSDCardPath()
				+ BaseActivity.getArchiveBean().getName();
		File temp = new File(userPath);
		if (!temp.exists()) {
			temp.mkdir();
		}
		// if (TextUtils.isEmpty(imagePath)) {
		imagePath = userPath + "/" + time + ".jpg";
		// }
		File outputImage = new File(imagePath);
		try {
			if (outputImage.exists())
				outputImage.delete();
			outputImage.createNewFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (Build.VERSION.SDK_INT >= 24) {
			/**
			 * 从Android7.0开始，直接使用本地的真是路径的URI被认为是不安全的，会抛出FileUriExposeException
			 * 而FileProvider是一种特殊的ContentProvider，可以给外部选择性的分享Uri，提高安全性
			 */
			imageUri = FileProvider.getUriForFile(GXYPlan_Activity.this,
					"com.example.testing.picturetest", outputImage);
		} else {

		}
		imageUri = Uri.fromFile(outputImage);
		System.out.println("image路径" + outputImage);
		// 启动相机
		Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
		intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
		intent.putExtra("android.intent.extra.quickCapture", true);
		startActivityForResult(intent, TAKE_PHOTO);
	}

	private static final int TAKE_PHOTO = 1;
	private static final int CHOOSE_PHOTO = 2;
	private static final int APPLY_PERMISSION = 3;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case TAKE_PHOTO:
			if (resultCode == RESULT_OK) {
				try {
					BitmapFactory.Options options = new BitmapFactory.Options();
					options.inPreferredConfig = Config.RGB_565;

					Bitmap bitmap = BitmapFactory.decodeStream(
							getContentResolver().openInputStream(imageUri),
							null, options);
					// 某些手机拍完照之后会自动旋转照片，以下代码把图片还原为旋转前状态
					int degree = PhotoRotateUtil.getBitmapDegree(imagePath);
					bitmap = PhotoRotateUtil.rotateBitmapByDegree(bitmap,
							degree);
					iv_mainImage.setImageBitmap(bitmap);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			break;
		}
		if (resultCode == JKTJActivity2.xueya_requestCode) {
			String dbp = data.getStringExtra("dbp");
			String sbp = data.getStringExtra("sbp");
			String pulse = data.getStringExtra("pulse");
			if (!TextUtils.isEmpty(dbp) && !TextUtils.isEmpty(sbp)
					&& !TextUtils.isEmpty(pulse)) {
				//血压
				setText(R.id.hypertension_edt_bloodpresure, sbp+"/"+dbp);
				//脉率
				setText(R.id.hypertension_edt_heartrate, pulse);
			}
		}
	}

	/***
	 * 检查编辑框。是否可以编辑的。
	 * 
	 * @return
	 */
	public boolean isEditTextOK() {
		if (TextUtils.isEmpty(getTextById(R.id.hypertension_turemethod))) {
			ToastTool.showShort(context, "随访方式不能为空！");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_reportdate))) {
			ToastTool.showShort(context, "随访日期不能为空!");
			return false;
		}
		// else if (TextUtils
		// .isEmpty(getTextById(R.id.hypertension_det_nextturedate))) {
		// ToastTool.showShort(context, "下次随访日期不能为空!");
		// return false;
		// }
		else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_edt_bloodpresure))
				|| getTextById(R.id.hypertension_edt_bloodpresure).equals("/")) {
			ToastTool.showShort(context, "血压不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_edt_heartrate))) {
			ToastTool.showShort(context, "心率不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_edt_smoking))) {
			ToastTool.showShort(context, "日吸烟量不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_edt_drinking))) {
			ToastTool.showShort(context, "日饮酒量不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_edt_targedrinkingtype))) {
			ToastTool.showShort(context, "饮酒种类不能为空!");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_edt_sport1))) {
			ToastTool.showShort(context, "运动次数不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_sce_drugobey))) {
			ToastTool.showShort(context, "服药依从性不能为空!");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_edt_weight))) {
			ToastTool.showShort(context, "体重不能为空!");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_edt_sport2))) {
			ToastTool.showShort(context, "运动时长不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_edt_targeweight))) {
			ToastTool.showShort(context, "目标体重不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_et_sce_salt))) {
			ToastTool.showShort(context, "摄盐情况不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_sce_mentaladjust))) {
			ToastTool.showShort(context, "心理调整不能为空!");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_sce_obey))) {
			ToastTool.showShort(context, "遵医行为不能为空!");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_symps))) {
			ToastTool.showShort(context, "症状不能为空!");
			return false;
		} else if (TextUtils.isEmpty(getTextById(R.id.hypertension_zhuangui))) {
			ToastTool.showShort(context, "转归不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_et_bingfazheng))) {
			ToastTool.showShort(context, "并发症不能为空!");
			return false;
		} else if (TextUtils
				.isEmpty(getTextById(R.id.hypertension_sce_tureclass))) {
			ToastTool.showShort(context, "此次随访分类不能为空!");
			return false;
		}
		return true;
	}

	private Visit_info getupload() {
		final Visit_info visit_info = new Visit_info();
		visit_info.setIdCard(mData.getIdCard());
		visit_info.setVisitDate(getTextById(R.id.hypertension_reportdate));
		visit_info.setNextDate(getTextById(R.id.hypertension_det_nextturedate));
		visit_info
				.setNoVisitReason(getTextById(R.id.hypertension_shifangyuanyin));
		// 下次随访日期暂时没有
		// visit_info.setVisitDate(getTextById(R.id.hypertension_det_nextturedate));
		// time = getIntent().getStringExtra("time");
		if (!TextUtils.isEmpty(time)) {
			visit_info.setTime(time);
		} else {

		}
		if (!TextUtils.isEmpty(imagePath)) {
			visit_info.setImagePath(imagePath);
		}
		// checkId是档案号码
		visit_info.setCheckid(mPlan.getRecordId());
		String yinjiu = getTextById(R.id.hypertension_edt_targedrinkingtype);
		String[] yinjius = yinjiu.split("\t");
		StringBuilder sb_yinjiu = new StringBuilder();
		for (int j = 0; j < yinjius.length; j++) {
			switch (yinjius[j]) {
			case "白酒(≥42度)":
				sb_yinjiu.append("1,");
				break;
			case "白酒(＜42度)":
				sb_yinjiu.append("2,");
				break;
			case "啤酒":
				sb_yinjiu.append("3,");
				break;
			case "黄酒、米酒":
				sb_yinjiu.append("4,");
				break;
			case "葡萄酒":
				sb_yinjiu.append("5,");
				break;
			case "其他":
				sb_yinjiu.append("9,");
				break;
			case "不饮酒":
				sb_yinjiu.append("10,");
				break;

			default:
				break;
			}
		}
		visit_info.setDrinkTypeCode(sb_yinjiu.toString());
		// 并发症
		String bingfazheng = getTextById(R.id.hypertension_et_bingfazheng);
		String[] bingfazhengs = bingfazheng.split("\t");
		StringBuilder sb_bingfazhengs = new StringBuilder();
		for (int j = 0; j < bingfazhengs.length; j++) {
			switch (bingfazhengs[j]) {
			case "无":
				sb_bingfazhengs.append("0,");
				break;
			case "缺血性卒中":
				sb_bingfazhengs.append("1,");
				break;
			case "脑出血":
				sb_bingfazhengs.append("2,");
				break;
			case "短暂性脑缺血发作":
				sb_bingfazhengs.append("3,");
				break;
			case "心肌梗死史":
				sb_bingfazhengs.append("4,");
				break;
			case "冠状动脉血运重建":
				sb_bingfazhengs.append("5,");
				break;
			case "心绞痛":
				sb_bingfazhengs.append("6,");
				break;
			case "充血性心力衰竭":
				sb_bingfazhengs.append("7,");
				break;
			case "糖尿病肾病":
				sb_bingfazhengs.append("8,");
				break;
			case "肾功能受损（血清肌酐）":
				sb_bingfazhengs.append("9,");
				break;
			case "视网膜病变":
				sb_bingfazhengs.append("10,");
				break;

			default:
				break;
			}
		}
		visit_info.setComplication(sb_bingfazhengs.toString());

		// 随访方式
		String FollowUpWays = getTextById(R.id.hypertension_turemethod);
		if ("门诊".equals(FollowUpWays))
			FollowUpWays = "1";
		else if ("家庭".equals(FollowUpWays))
			FollowUpWays = "2";
		else if ("电话".equals(FollowUpWays)) {
			FollowUpWays = "3";
		} else if ("短信".equals(FollowUpWays)) {
			FollowUpWays = "4";
		} else if ("网络".equals(FollowUpWays)) {
			FollowUpWays = "5";
		} else if ("其他".equals(FollowUpWays)) {
			FollowUpWays = "9";
		}
		// 门诊"/>
		// <item key="2" text="家庭"/>
		// <item key="3" text="电话"/>
		// <item key="4" text="短信" pyCode="dx"/>
		// <item key="5" text="网络" pyCode="wl"/>
		// <item key="9" text="其他" pyCode="qt"/>）
		visit_info.setVisitType(FollowUpWays);
		String zhuangui = getTextById(R.id.hypertension_zhuangui);
		String visitEffect = "";
		if ("继续随访".equals(zhuangui)) {
			visitEffect = "1";
		} else if ("暂时失访".equals(zhuangui)) {
			visitEffect = "2";
		} else if ("终止管理".equals(zhuangui)) {
			visitEffect = "9";
		}
		visit_info.setVisitEffect(visitEffect);
		// 原因
		String reason = getTextById(R.id.hypertension_referral_reason);
		visit_info.setNoVisitReason(reason);
		// 目前症状。
		String zhengzhuangstr = getTextById(R.id.hypertension_symps);
		StringBuilder sb_zhuangzhuang = new StringBuilder();
		if (zhengzhuangstr != null && zhengzhuangstr.length() > 0) {
			String[] ss = zhengzhuangstr.split("\t");
			for (String s : ss) {
				switch (s) {
				case "无症状":
					sb_zhuangzhuang.append("9" + ",");
					break;
				case "头痛头晕":
					sb_zhuangzhuang.append("1" + ",");
					break;
				case "恶心呕吐":
					sb_zhuangzhuang.append("2" + ",");
					break;
				case "眼花耳鸣":
					sb_zhuangzhuang.append("3" + ",");
					break;
				case "呼吸困难":
					sb_zhuangzhuang.append("4" + ",");
					break;
				case "心悸胸闷":
					sb_zhuangzhuang.append("5" + ",");
					break;
				case "鼻衄出血不止":
					sb_zhuangzhuang.append("6" + ",");
					break;
				case "四肢发麻":
					sb_zhuangzhuang.append("7" + ",");
					break;
				case "下肢水肿":
					sb_zhuangzhuang.append("8" + ",");
					break;
				default:
					break;
				}
				if (s.contains("其他") && s.contains("(")) {
					s = s.replace("其他", "").replace(")", "").replace("(", "");
					// 其他症状
					sb_zhuangzhuang.append("10" + "," + s);
					visit_info.setOtherSymptoms(s);
				} else {
					visit_info.setOtherSymptoms("");
				}
			}
		}
		visit_info.setCurrentSymptoms(sb_zhuangzhuang.toString());
		String gxy = getTextById(R.id.hypertension_edt_bloodpresure);
		if (!TextUtils.isEmpty(gxy)) {
			String[] strs = gxy.split("/");
			if (strs != null && strs.length == 2) {
				visit_info.setConstriction(strs[0]);
				visit_info.setDiastolic(strs[1]);
			}
		}

		visit_info.setWeight(getTextById(R.id.hypertension_edt_weight));
		visit_info
				.setTargetWeight(getTextById(R.id.hypertension_edt_targeweight));
		visit_info.setBmi(getTextById(R.id.hypertension_edt_index));
		visit_info.setHeartRate(getTextById(R.id.hypertension_edt_heartrate));
		visit_info
				.setTargetHeartRate(getTextById(R.id.hypertension_edt_targeheartrate));

		visit_info.setOtherSigns(getTextById(R.id.hypertension_edt_signother));
		visit_info.setSmokeCount(getTextById(R.id.hypertension_edt_smoking));
		visit_info
				.setTargetSmokeCount(getTextById(R.id.hypertension_edt_targesmoking));
		// visit_info.setDrinkTypeCode(getTextById(R.id.hypertension_edt_drinking));//饮类型暂时还没有写好。
		visit_info.setDrinkCount(getTextById(R.id.hypertension_edt_drinking));
		visit_info
				.setTargetDrinkCount(getTextById(R.id.hypertension_edt_targedrinking));
		visit_info.setTrainTimesWeek(getTextById(R.id.hypertension_edt_sport1));
		visit_info.setTrainMinute(getTextById(R.id.hypertension_edt_sport2));
		visit_info
				.setTargetTrainTimesWeek(getTextById(R.id.hypertension_edt_targesport1));
		visit_info
				.setTargetTrainMinute(getTextById(R.id.hypertension_edt_targesport2));
		String yan = getTextById(R.id.hypertension_et_sce_salt);
		if ("轻".equals(yan)) {
			visit_info.setSalt("1");// 日吃盐
		} else if ("中".equals(yan)) {
			visit_info.setSalt("2");// 日吃盐
		} else if ("重".equals(yan)) {
			visit_info.setSalt("3");// 日吃盐
		}
		String targetyan = getTextById(R.id.hypertension_et_sce_targesalt);
		if ("轻".equals(targetyan)) {
			visit_info.setTargetSalt("1");// 日吃盐目标
		} else if ("中".equals(targetyan)) {
			visit_info.setTargetSalt("2");// 日吃盐目标
		} else if ("重".equals(targetyan)) {
			visit_info.setTargetSalt("3");// 日吃盐目标
		}
		// 心理调整
		String PsychologicalAdjustment = getTextById(R.id.hypertension_sce_mentaladjust);
		if ("良好".equals(PsychologicalAdjustment))
			PsychologicalAdjustment = "1";
		else if ("一般".equals(PsychologicalAdjustment))
			PsychologicalAdjustment = "2";
		else
			PsychologicalAdjustment = "3";
		visit_info.setPsychologyChange(PsychologicalAdjustment);

		// 遵医行为
		String ComplianceBehavior = getTextById(R.id.hypertension_sce_obey);
		if ("良好".equals(ComplianceBehavior)) {
			ComplianceBehavior = "1";
		} else if ("一般".equals(ComplianceBehavior)) {
			ComplianceBehavior = "2";
		} else {
			ComplianceBehavior = "3";
		}
		visit_info.setObeyDoctor(ComplianceBehavior);

		// 辅助检查
		String fuzhujiancha = getTextById(R.id.edt_Auxiliary_examination);
		visit_info.setAuxiliaryCheck(fuzhujiancha);
		// 饮食
		String yinshi = getTextById(R.id.hypertension_et_yinshi);
		if ("规律".equals(yinshi)) {
			visit_info.setDiet("1");
		} else if ("不规律".equals(yinshi)) {
			visit_info.setDiet("2");
		}

		// 服药依从性
		String MedicationCompliance = getTextById(R.id.hypertension_sce_drugobey);
		if ("规律".equals(MedicationCompliance)) {
			MedicationCompliance = "1";
		} else if ("间断".equals(MedicationCompliance)) {
			MedicationCompliance = "2";
		} else if ("不服药".equals(MedicationCompliance)) {
			MedicationCompliance = "3";
		} else if ("拒绝服药".equals(MedicationCompliance)) {
			MedicationCompliance = "4";
		}
		visit_info.setMedicine(MedicationCompliance);

		// 药物不良反应
		String Str = getTextById(R.id.hypertension_scedt_drugreaction);
		if (Str != null) {
			if ("无".equals(Str)) {
				visit_info.setMedicineBadEffect("1");
			} else if (Str.contains("有")) {
				visit_info.setMedicineBadEffect("2");
			}
		}
		// 危险因素还没判断里面内容
		String wxys = getTextById(R.id.hypertension_et_riskiness);
		String[] wxyss = wxys.split("\t");
		StringBuilder sb_wxys = new StringBuilder();
		for (int i = 0; i < wxyss.length; i++) {
			switch (wxyss[i]) {
			case "无":
				sb_wxys.append("0,");
				break;
			case "男性＞55岁或女性＞65岁":
				sb_wxys.append("1,");
				break;
			case "吸烟":
				sb_wxys.append("2,");
				break;
			case "血脂异常":
				sb_wxys.append("3,");
				break;
			case "早发心血管疾病家族史":
				sb_wxys.append("4,");
				break;
			case "腹型肥胖或肥胖":
				sb_wxys.append("5,");
				break;
			case "缺乏体力活动":
				sb_wxys.append("6,");
				break;
			case "高敏C反应蛋白≥3mg/L或C反应蛋白≥10mg/L":
				sb_wxys.append("7,");
				break;
			case "血压异常":
				sb_wxys.append("8,");
				break;
			default:
				break;
			}
		}
		visit_info.setRiskiness(sb_wxys.toString());
		visit_info.setTargetHurt(getTextById(R.id.hypertension_et_targetHurt));
		String jiazhong = getTextById(R.id.hypertension_et_bingfazhengjiazhong);
		if ("是".equals(jiazhong)) {
			jiazhong = "1";
		} else if ("否".equals(jiazhong)) {
			jiazhong = "2";
		}

		// 危险分层
		visit_info.setComplicationIncrease(jiazhong);
		String weixian = getTextById(R.id.hypertension_et_weixian);
		if ("低危".equals(weixian)) {
			weixian = "1";
		} else if ("中危".equals(weixian)) {
			weixian = "2";
		} else if ("高危".equals(weixian)) {
			weixian = "3";
		} else if ("很高危".equals(weixian)) {
			weixian = "4";
		}
		// 危险分层
		String loseWeight = getTextById(R.id.hypertension_edt_loseWeight);
		if ("不需要".equals(loseWeight)) {
			loseWeight = "1";
		} else if ("需要".equals(loseWeight)) {
			loseWeight = "2";
		}
		visit_info.setLoseWeight(loseWeight);
		visit_info.setRiskLevel(weixian);
		String suifangfenlei = getTextById(R.id.hypertension_sce_tureclass);
		if ("控制满意".equals(suifangfenlei)) {
			suifangfenlei = "1";
		} else if ("控制不满意".equals(suifangfenlei)) {
			suifangfenlei = "2";
		} else if ("不良反应".equals(suifangfenlei)) {
			suifangfenlei = "3";
		} else if ("并发症".equals(suifangfenlei)) {
			suifangfenlei = "4";
		}
		visit_info.setVisitEvaluate(suifangfenlei);
		List<MedicineDesc> lists = new ArrayList<MedicineDesc>();
		MedicineDesc oneBean = null;
		if (!TextUtils.isEmpty(otherMedicineDesc1_et.getText().toString())) {
			oneBean = new MedicineDesc();
			oneBean.setOtherMedicineDesc(otherMedicineDesc1_et.getText()
					.toString());
			oneBean.setMedicineFrequency(medicineFrequency1_et.getText()
					.toString());
			oneBean.setMedicineDosage(medicineDosage1_et.getText().toString());
			oneBean.setDays("1");
			lists.add(oneBean);
		}
		if (!TextUtils.isEmpty(otherMedicineDesc2_et.getText().toString())) {
			oneBean = new MedicineDesc();
			oneBean.setOtherMedicineDesc(otherMedicineDesc2_et.getText()
					.toString());
			oneBean.setMedicineFrequency(medicineFrequency2_et.getText()
					.toString());
			oneBean.setMedicineDosage(medicineDosage2_et.getText().toString());
			oneBean.setDays("1");
			lists.add(oneBean);
		}
		if (!TextUtils.isEmpty(otherMedicineDesc3_et.getText().toString())) {
			oneBean = new MedicineDesc();
			oneBean.setOtherMedicineDesc(otherMedicineDesc3_et.getText()
					.toString());
			oneBean.setMedicineFrequency(medicineFrequency3_et.getText()
					.toString());
			oneBean.setMedicineDosage(medicineDosage3_et.getText().toString());
			oneBean.setDays("1");
			lists.add(oneBean);
		}
		if (!TextUtils.isEmpty(otherMedicineDesc4_et.getText().toString())) {
			oneBean = new MedicineDesc();
			oneBean.setOtherMedicineDesc(otherMedicineDesc4_et.getText()
					.toString());
			oneBean.setMedicineFrequency(medicineFrequency4_et.getText()
					.toString());
			oneBean.setMedicineDosage(medicineDosage4_et.getText().toString());
			oneBean.setDays("1");
			lists.add(oneBean);
		}
		visit_info.setXml(XmlTool.getMedicineDescsXml(lists));
		visit_info.setMedicineDescs(lists);
		return visit_info;
	}

	protected void upload() {
		if (!isEditTextOK()) {
			return;
		}
		if (mData == null) {
			return;
		}
		Visit_info visit_info = getupload();
		// 这里将高血压的bean类转化为需要的json数据。
		final Visit visit = new Visit();
		// 随访标识
		visit.setVisitId("");
		// 档案编码
		visit.setPhrId(mPlan.getRecordId());
		// empiid
		visit.setEmpiId(mData.getEmpiId());
		visit.setIdCard(mData.getIdCard());
		visit.setPlanId_GXY(mPlan.getPlanId());
		visit.setVisitDate(visit_info.getVisitDate());
		visit.setVisitDoctor(hypertension_edt_turedoctor.getText().toString());// 随访医生
		visit.setVisitUser(hypertension_edt_turedoctor.getText().toString());// 随访医生
		String doctor = SharedpreferenceUtil.getOnDoctorId(context, "");
		visit.setVisitDoctor(doctor);//
		// 随访医生
		visit.setVisitUser(doctor);//
		// 随访医生
		String token = SharedpreferenceUtil.getToken(context, "");
		String util = "";
		if (!TextUtils.isEmpty(token)) {
			util = token.substring(0, token.length() - 3);
		}
		visit.setVisitUnit(util);// 随访机构。
		visit.setVisitWay(visit_info.getVisitType());
		visit.setVisitType(visit_info.getVisitType());
		visit.setNextDate(visit_info.getNextDate());// 下次随访日期
		visit.setVisitEffect(visit_info.getVisitEffect());
		visit.setNoVisitReason(visit_info.getNoVisitReason());
		visit.setDiabetesType("");// 暂时没实现 病例种类
		visit.setDiabetesChange("");// 发生转型
		visit.setConstriction(StringUtils.parseIntByStr(visit_info
				.getConstriction()));// 收缩压
		visit.setDiastolic(StringUtils.parseIntByStr(visit_info.getDiastolic()));
		visit.setWeight(StringUtils.parseDoubleByStr(visit_info.getWeight()));
		visit.setTargetWeight(StringUtils.parseDoubleByStr(visit_info
				.getTargetWeight()));
		visit.setBmi(StringUtils.parseDoubleByStr(visit_info.getBmi()));
		// data.setTargetBmi(visit_info.getBmi());//目标的bmi、暂时没实现
		visit.setOtherSigns(visit_info.getOtherSigns());
		visit.setDiet(visit_info.getDiet());
		visit.setSmokeCount(StringUtils.parseIntByStr(visit_info
				.getSmokeCount()));
		visit.setTargetSmokeCount(StringUtils.parseIntByStr(visit_info
				.getTargetSmokeCount()));
		visit.setTrainTimesWeek(StringUtils.parseIntByStr(visit_info
				.getTrainTimesWeek()));
		visit.setTargetTrainTimesWeek(StringUtils.parseIntByStr(visit_info
				.getTargetTrainTimesWeek()));
		visit.setTrainMinute(StringUtils.parseIntByStr(visit_info
				.getTrainMinute()));
		visit.setTargetTrainMinute(StringUtils.parseIntByStr(visit_info
				.getTargetTrainMinute()));
		visit.setPsychologyChange(visit_info.getPsychologyChange());
		visit.setObeyDoctor(visit_info.getObeyDoctor());
		String lastModifyDate = TimeHelper.getJKTJCheckDate();
		visit.setLastModifyUser(doctor);// 最后修改人
		visit.setLastModifyUnit(util);// 最后修改单位
		visit.setLastModifyDate(lastModifyDate);// 最后修改日期
		visit.setManaUnitId(util);// 管辖机构
		visit.setManaDoctorId(doctor);// 责任医生
		// 高血压特有的设置
		HypertensionVisit hv = new HypertensionVisit();
		hv.setSalt(StringUtils.parseIntByStr(visit_info.getSalt()));
		hv.setTargetSalt(StringUtils.parseIntByStr(visit_info.getTargetSalt()));
		hv.setVisitEvaluate(visit_info.getVisitEvaluate());
		hv.setMedicine(visit_info.getMedicine());
		hv.setAuxiliaryCheck(visit_info.getAuxiliaryCheck());
		hv.setHeartRate(StringUtils.parseIntByStr(visit_info.getHeartRate()));
		hv.setTargetHeartRate(StringUtils.parseIntByStr(visit_info
				.getTargetHeartRate()));
		hv.setLoseWeight(visit_info.getLoseWeight());
		String dtc = visit_info.getDrinkTypeCode();
		if (!TextUtils.isEmpty(dtc) && dtc.endsWith(",")) {
			dtc = dtc.substring(0, dtc.length() - 1);
		}
		hv.setDrinkTypeCode(dtc);
		hv.setDrinkCount(StringUtils.parseIntByStr(visit_info.getDrinkCount()));
		hv.setTargetDrinkCount(StringUtils.parseIntByStr(visit_info
				.getTargetDrinkCount()));
		hv.setLoseWeight(visit_info.getLoseWeight());
		String cs = visit_info.getCurrentSymptoms();
		if (!TextUtils.isEmpty(dtc) && cs.endsWith(",")) {
			cs = cs.substring(0, cs.length() - 1);
		}
		hv.setCurrentSymptoms(cs);
		hv.setOtherSymptoms(visit_info.getOtherSymptoms());
		String cc = visit_info.getComplication();
		if (!TextUtils.isEmpty(cc) && cc.endsWith(",")) {
			cc = cc.substring(0, cc.length() - 1);
		}
		hv.setComplication(cc);
		String th = visit_info.getTargetHurt();
		String targetHurt = "0";
		switch (th) {
		case "无":
			targetHurt = "0";
			break;
		case "左心室肥厚":
			targetHurt = "1";
			break;
		case "动脉壁增厚":
			targetHurt = "2";
			break;
		case "血清肌酐轻度升高":
			targetHurt = "3";
			break;
		case "微量白蛋白尿":
			targetHurt = "4";
			break;
		default:
			break;
		}
		hv.setTargetHurt(targetHurt);

		hv.setComplicationIncrease(visit_info.getComplicationIncrease());
		hv.setRiskLevel(visit_info.getRiskLevel());
		// hv.setCbyx(visit_info.get)//初步印象
		hv.setReferralReason(visit_info.getNoVisitReason());
		// hv.setZljg("");//治疗经过
		// hv.setZzys(zzys);//转诊医生
		// hv.setLxdh(lxdh)(zzys);//联系电话
		// hv.setZzjg(zzjg)(zzys);//转诊机构
		// hv.setZzsj(zzsj)(zzys);//转诊时间
		// hv.setAgencyAndDept(agencyAndDept)(zzys);//接诊机构及科室
		// hv.setJzks(jzks)(zzys);//接诊科室
		// hv.setJzys(jzys)(zzys);//接诊医生
		List<MedicineDesc> descs = visit_info.getMedicineDescs();
		List<HypertensionMedicines> hms = new ArrayList<HypertensionMedicines>();
		if (descs != null && descs.size() > 0) {
			for (int i = 0; i < descs.size(); i++) {
				MedicineDesc desc = descs.get(i);
				HypertensionMedicines hm = new HypertensionMedicines();
				hm.setMedicineName(desc.getOtherMedicineDesc());// 名称
				hm.setMedicineId(VisitContants.getGXYCodeByYaowuName(desc
						.getOtherMedicineDesc()));// id
				hm.setMedicineFrequency(StringUtils.parseIntByStr(desc
						.getMedicineFrequency()));// 次数
				hm.setDays(StringUtils.parseIntByStr(desc.getDays()));// 天数
				hm.setMedicineDosage(StringUtils.parseDoubleByStr(desc
						.getMedicineDosage()));// 每次剂量
				hm.setMedicineUnit("mg");// 计量单位
				// hm.setCreateDate(createDate);//开药时间默认当天
				// hm.setMedicineTotalDosage(medicineTotalDosage);//总剂量
				// hm.setOtherMedicineDesc();//其他用药描述
				hms.add(hm);
			}
		}
		hv.setHypertensionMedicines(hms);
		visit.setHypertensionVisit(hv);// 高血压随访
		// data.setDiabetesVisit(diabetesVisit);//糖尿病随访
		// 完成一个json的上传数据填充
		// 添加到数据库
		String uploadStr = XmlTool.GXY2String(visit_info);
		boolean b = DBService.add(visit_info);
		final String uploadTime = visit_info.getTime();
		visit.setAppvisitId(uploadTime);
		String imagePath = visit_info.getImagePath();
		if (!TextUtils.isEmpty(imagePath)) {
			WebService.uploadPicVisit(context, imagePath, new StringCallback() {

				@Override
				public void onSuccess(String str, Call call, Response response) {
					// 查看
					String fileId = "";
					try {
						JSONObject strJsonObject = new JSONObject(str);
						JSONArray dataArray = strJsonObject
								.optJSONArray("data");
						if (dataArray != null && dataArray.length() > 0) {
							JSONObject data0;
							data0 = (JSONObject) dataArray.get(0);
							fileId = data0.optString("fileId");
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
					System.out.println("返回的图片的信息：" + str);
					if (!TextUtils.isEmpty(fileId)) {
						visit.setPhoto(fileId);
					}
					WebService.addVisit(context, uploadTime, jsonHandler,
							visit, UploadRecord.Type.GXY, mData.getIdCard());
				}

				@Override
				public void onError(Call call, Response response, Exception e) {
					super.onError(call, response, e);
					WebService.addVisit(context, uploadTime, jsonHandler,
							visit, UploadRecord.Type.GXY, mData.getIdCard());
				}

				@Override
				public void onBefore(BaseRequest request) {
					super.onBefore(request);
					System.out.println("执行了请求前");
				}

				@Override
				public void onAfter(String t, Exception e) {
					super.onAfter(t, e);
					System.out.println("执行了请求后");
				}
			});
		} else {
			WebService.addVisit(context, uploadTime, jsonHandler, visit,
					UploadRecord.Type.GXY, mData.getIdCard());
		}

	}

	private static final int what_success_ok = 65;
	private static final int what_failed = 77;
	private static final int what_error = 87;
	Handler jsonHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case what_success_ok:
				ToastTool.showLong(context, "上传成功");
				break;
			case what_failed:
				ToastTool.showLong(context, "上传错误");
				break;
			case what_error:
				ToastTool.showLong(context, "访问出错，请检查网络或配置信息");
				break;
			}
		};
	};

	public void setDataToUI(Visit_info visit_info) {
		// 暂时不知道这个什么意思。
		setText(R.id.hypertension_turenum, mPlan.getRecordId());// 先放身份证号。因为编号不知道是什么
		setText(R.id.hypertension_reportdate, visit_info.getVisitDate());
		setText(R.id.hypertension_det_nextturedate, visit_info.getNextDate());
		setText(R.id.hypertension_turename, mData.getPersonName());
		String sfDate = TimeHelper.getJKTJCheckDate();
		String afterDate = TimeHelper.getAfter15DaysDate();
		setText(R.id.hypertension_reportdate, sfDate);
		// setText(R.id.hypertension_det_nextturedate, afterDate);
		// setText(R.id.hypertension_reportdate, visit_info.getTime());
		setText(R.id.hypertension_shifangyuanyin, visit_info.getNoVisitReason());
		// 随访方式
		String FollowUpWays = visit_info.getVisitType();
		if ("1".equals(FollowUpWays)) {
			FollowUpWays = "门诊";
		} else if ("2".equals(FollowUpWays))
			FollowUpWays = "家庭";
		else if ("3".equals(FollowUpWays)) {
			FollowUpWays = "电话";
		} else if ("4".equals(FollowUpWays)) {
			FollowUpWays = "短信";
		} else if ("5".equals(FollowUpWays)) {
			FollowUpWays = "网络";
		} else if ("9".equals(FollowUpWays)) {
			FollowUpWays = "其他";
		}
		String temp = visit_info.getImagePath();
		if (!TextUtils.isEmpty(temp)) {
			imagePath = temp;
		}
		if (!TextUtils.isEmpty(imagePath)) {
			BitmapFactory.Options options = new BitmapFactory.Options();
			options.inPreferredConfig = Config.RGB_565;
			Bitmap imageBitmap = BitmapFactory.decodeFile(imagePath, options);
			if (imageBitmap != null) {
				iv_mainImage.setImageBitmap(imageBitmap);
			}
		}
		// 饮食
		setText(R.id.hypertension_turemethod, FollowUpWays);
		// 饮酒类型
		String yinjiu = visit_info.getDrinkTypeCode();
		String[] yinjius = yinjiu.split(",");
		StringBuilder sb_yinjiu = new StringBuilder();
		for (int j = 0; j < yinjius.length; j++) {
			switch (yinjius[j]) {
			case "1":
				sb_yinjiu.append("白酒(≥42度)\t");
				break;
			case "2":
				sb_yinjiu.append("白酒(＜42度)\t");
				break;
			case "3":
				sb_yinjiu.append("啤酒\t");
				break;
			case "4":
				sb_yinjiu.append("黄酒、米酒\t");
				break;
			case "5":
				sb_yinjiu.append("葡萄酒\t");
				break;
			case "9":
				sb_yinjiu.append("其他\t");
				break;
			case "10":
				sb_yinjiu.append("不饮酒\t");
				break;
			default:
				break;
			}
		}
		setText(R.id.hypertension_edt_targedrinkingtype, sb_yinjiu.toString());
		String visitEffect = visit_info.getVisitEffect();
		if ("1".equals(visitEffect)) {
			visitEffect = "继续随访";
		} else if ("2".equals(visitEffect)) {
			visitEffect = "暂时失访";
		} else if ("3".equals(visitEffect)) {
			visitEffect = "终止管理";
		}
		// 是否需要减轻体重
		setText(R.id.hypertension_zhuangui, visitEffect);
		String lostWeight = visit_info.getLoseWeight();
		if ("1".equals(lostWeight)) {
			lostWeight = "不需要";
		} else if ("2".equals(lostWeight)) {
			lostWeight = "需要";
		}
		setText(R.id.hypertension_edt_loseWeight, lostWeight);
		// 原因
		setText(R.id.hypertension_referral_reason,
				visit_info.getNoVisitReason());
		// 目前症状。
		String zhengzhuangstr = visit_info.getCurrentSymptoms();
		StringBuilder sb_zhuangzhuang = new StringBuilder();
		if (zhengzhuangstr != null && zhengzhuangstr.length() > 0) {
			String[] ss = zhengzhuangstr.split(",");
			for (String s : ss) {
				switch (s) {
				case "9":
					sb_zhuangzhuang.append("无症状" + "\t");
					break;
				case "1":
					sb_zhuangzhuang.append("头痛头晕" + "\t");
					break;
				case "2":
					sb_zhuangzhuang.append("恶心呕吐" + "\t");
					break;
				case "3":
					sb_zhuangzhuang.append("眼花耳鸣" + "\t");
					break;
				case "4":
					sb_zhuangzhuang.append("呼吸困难" + "\t");
					break;
				case "5":
					sb_zhuangzhuang.append("心悸胸闷" + "\t");
					break;
				case "6":
					sb_zhuangzhuang.append("鼻衄出血不止" + "\t");
					break;
				case "7":
					sb_zhuangzhuang.append("四肢发麻" + "\t");
					break;
				case "8":
					sb_zhuangzhuang.append("下肢水肿" + "\t");
					break;
				case "10":
					sb_zhuangzhuang.append("其他("
							+ visit_info.getOtherSymptoms() + ")");
					break;
				}
			}
		}
		setText(R.id.hypertension_symps, sb_zhuangzhuang.toString());
		// 心率
		setText(R.id.hypertension_edt_heartrate, visit_info.getHeartRate());
		// 血压
		setText(R.id.hypertension_edt_bloodpresure,
				visit_info.getConstriction() + "/" + visit_info.getDiastolic());
		// 体重
		setText(R.id.hypertension_edt_weight, visit_info.getWeight());
		setText(R.id.hypertension_edt_index, visit_info.getBmi());
		setText(R.id.hypertension_edt_targeweight, visit_info.getTargetWeight());

		setText(R.id.hypertension_edt_targeheartrate,
				visit_info.getTargetHeartRate());
		setText(R.id.hypertension_edt_signother, visit_info.getOtherSigns());
		setText(R.id.hypertension_edt_smoking, visit_info.getSmokeCount());
		setText(R.id.hypertension_edt_targesmoking,
				visit_info.getTargetSmokeCount());
		setText(R.id.hypertension_edt_drinking, visit_info.getDrinkCount());
		// visit_info.setDrinkTypeCode(getTextById(R.id.hypertension_edt_drinking));//饮类型暂时还没有写好。
		setText(R.id.hypertension_edt_targedrinking,
				visit_info.getTargetDrinkCount());
		setText(R.id.hypertension_edt_sport1, visit_info.getTrainTimesWeek());
		setText(R.id.hypertension_edt_sport2, visit_info.getTrainMinute());
		setText(R.id.hypertension_edt_targesport1,
				visit_info.getTargetTrainTimesWeek());
		setText(R.id.hypertension_edt_targesport2,
				visit_info.getTargetTrainMinute());
		String yan = visit_info.getSalt();
		if ("1".equals(yan)) {
			setText(R.id.hypertension_et_sce_salt, "轻");
		} else if ("2".equals(yan)) {
			setText(R.id.hypertension_et_sce_salt, "中");
		} else if ("3".equals(yan)) {
			setText(R.id.hypertension_et_sce_salt, "重");
		}
		String targetyan = visit_info.getTargetSalt();
		if ("1".equals(targetyan)) {
			setText(R.id.hypertension_et_sce_targesalt, "轻");
		} else if ("2".equals(targetyan)) {
			setText(R.id.hypertension_et_sce_targesalt, "中");
		} else if ("3".equals(targetyan)) {
			setText(R.id.hypertension_et_sce_targesalt, "重");
		}
		// 心理调整
		String PsychologicalAdjustment = visit_info.getPsychologyChange();
		if ("1".equals(PsychologicalAdjustment)) {
			PsychologicalAdjustment = "良好";
		} else if ("2".equals(PsychologicalAdjustment)) {
			PsychologicalAdjustment = "一般";
		} else if ("3".equals(PsychologicalAdjustment)) {
			PsychologicalAdjustment = "差";
		}
		setText(R.id.hypertension_sce_mentaladjust, PsychologicalAdjustment);

		// 遵医行为
		String ComplianceBehavior = visit_info.getObeyDoctor();
		if ("1".equals(ComplianceBehavior)) {
			ComplianceBehavior = "良好";
		} else if ("2".equals(ComplianceBehavior)) {
			ComplianceBehavior = "一般";
		} else if ("3".equals(ComplianceBehavior)) {
			ComplianceBehavior = "差";
		}
		setText(R.id.hypertension_sce_obey, ComplianceBehavior);

		// 辅助检查
		setText(R.id.edt_Auxiliary_examination, visit_info.getAuxiliaryCheck());

		// 饮食
		String yinshi = visit_info.getDiet();
		if ("1".equals(yinshi)) {
			setText(R.id.hypertension_et_yinshi, "规律");
		} else if ("2".equals(yinshi)) {
			setText(R.id.hypertension_et_yinshi, "不规律");
		}

		// 服药依从性
		String MedicationCompliance = visit_info.getMedicine();
		if ("1".equals(MedicationCompliance)) {
			MedicationCompliance = "规律";
		} else if ("2".equals(MedicationCompliance)) {
			MedicationCompliance = "间断";
		} else if ("3".equals(MedicationCompliance)) {
			MedicationCompliance = "不服药";
		}
		setText(R.id.hypertension_sce_drugobey, MedicationCompliance);

		// 药物不良反应
		String Str = visit_info.getMedicineBadEffect();
		if (Str != null) {
			if ("1".equals(Str)) {
				Str = "无";
			} else if (Str.contains("2")) {
				Str = "有";
			}
		}
		setText(R.id.hypertension_scedt_drugreaction, Str);

		// 危险因素还没判断里面内容
		// visit_info.setRiskiness(getTextById(R.id.hypertension_et_riskiness));
		// 危险因素还没判断里面内容
		String wxys = visit_info.getRiskiness();
		String[] wxyss = wxys.split(",");
		StringBuilder sb_wxys = new StringBuilder();
		for (int i = 0; i < wxyss.length; i++) {
			switch (wxyss[i]) {
			case "0":
				sb_wxys.append("无\t");
				break;
			case "1":
				sb_wxys.append("男性＞55岁或女性＞65岁\t");
				break;
			case "2":
				sb_wxys.append("吸烟\t");
				break;
			case "3":
				sb_wxys.append("血脂异常\t");
				break;
			case "4":
				sb_wxys.append("早发心血管疾病家族史\t");
				break;
			case "5":
				sb_wxys.append("腹型肥胖或肥胖\t");
				break;
			case "6":
				sb_wxys.append("缺乏体力活动\t");
				break;
			case "7":
				sb_wxys.append("高敏C反应蛋白≥3mg/L或C反应蛋白≥10mg/L\t");
				break;
			case "8":
				sb_wxys.append("血压异常\t");
				break;
			default:
				break;
			}
		}
		setText(R.id.hypertension_et_riskiness, sb_wxys.toString());
		setText(R.id.hypertension_et_targetHurt, visit_info.getTargetHurt());
		String bingfazheng = visit_info.getComplication();
		String[] bingfazhengs = bingfazheng.split(",");
		StringBuilder sb_bingfazhengs = new StringBuilder();
		for (int j = 0; j < bingfazhengs.length; j++) {
			switch (bingfazhengs[j]) {
			case "0":
				sb_bingfazhengs.append("无" + "\t");
				break;
			case "1":
				sb_bingfazhengs.append("缺血性卒中" + "\t");
				break;
			case "2":
				sb_bingfazhengs.append("脑出血" + "\t");
				break;
			case "3":
				sb_bingfazhengs.append("短暂性脑缺血发作" + "\t");
				break;
			case "4":
				sb_bingfazhengs.append("心肌梗死史" + "\t");
				break;
			case "5":
				sb_bingfazhengs.append("冠状动脉血运重建" + "\t");
				break;
			case "6":
				sb_bingfazhengs.append("心绞痛" + "\t");
				break;
			case "7":
				sb_bingfazhengs.append("充血性心力衰竭" + "\t");
				break;
			case "8":
				sb_bingfazhengs.append("糖尿病肾病" + "\t");
				break;
			case "9":
				sb_bingfazhengs.append("肾功能受损（血清肌酐）" + "\t" + "\t");
				break;
			case "10":
				sb_bingfazhengs.append("视网膜病变" + "\t");
				break;
			default:
				break;
			}
		}
		setText(R.id.hypertension_et_bingfazheng, sb_bingfazhengs.toString());
		String jiazhong = visit_info.getComplicationIncrease();
		if ("1".equals(jiazhong)) {
			jiazhong = "是";
		} else if ("2".equals(jiazhong)) {
			jiazhong = "否";
		}
		setText(R.id.hypertension_et_bingfazhengjiazhong, jiazhong);

		// 危险分层
		String weixian = visit_info.getRiskLevel();
		if ("1".equals(weixian)) {
			weixian = "低危";
		} else if ("2".equals(weixian)) {
			weixian = "中危";
		} else if ("3".equals(weixian)) {
			weixian = "高危";
		} else if ("4".equals(weixian)) {
			weixian = "很高危";
		}
		setText(R.id.hypertension_et_weixian, weixian);
		String suifangfenlei = visit_info.getVisitEvaluate();
		if ("1".equals(suifangfenlei)) {
			suifangfenlei = "控制满意";
		} else if ("2".equals(suifangfenlei)) {
			suifangfenlei = "控制不满意";
		} else if ("3".equals(suifangfenlei)) {
			suifangfenlei = "不良反应";
		} else if ("4".equals(suifangfenlei)) {
			suifangfenlei = "并发症";
		}
		setText(R.id.hypertension_sce_tureclass, suifangfenlei);
		String xml = visit_info.getXml();
		List<MedicineDesc> lists = XmlTool.parseMedicineDescByxml(xml);
		if (lists != null && lists.size() > 0) {
			int index = 0;
			MedicineDesc bean = null;
			for (int i = 0; i < lists.size(); i++) {
				bean = lists.get(i);
				if (index == 0) {
					otherMedicineDesc1_et.setText(bean.getOtherMedicineDesc());
					medicineFrequency1_et.setText(bean.getMedicineFrequency());
					medicineDosage1_et.setText(bean.getMedicineDosage());
					index = 1;
					continue;
				}
				if (index == 1) {
					otherMedicineDesc2_et.setText(bean.getOtherMedicineDesc());
					medicineFrequency2_et.setText(bean.getMedicineFrequency());
					medicineDosage2_et.setText(bean.getMedicineDosage());
					index = 2;
					continue;
				}
				if (index == 2) {
					otherMedicineDesc3_et.setText(bean.getOtherMedicineDesc());
					medicineFrequency3_et.setText(bean.getMedicineFrequency());
					medicineDosage3_et.setText(bean.getMedicineDosage());
					index = 3;
					continue;
				}
				if (index == 3) {
					otherMedicineDesc4_et.setText(bean.getOtherMedicineDesc());
					medicineFrequency4_et.setText(bean.getMedicineFrequency());
					medicineDosage4_et.setText(bean.getMedicineDosage());
				}
			}
		}
	}

	private void setChoiceEditText() {
		setChoiceEditText(R.id.hypertension_et_targetHurt, new String[] { "无",
				"左心室肥厚", "动脉壁增厚", "血清肌酐轻度升高", "微量白蛋白尿" }, null);
		setChoiceEditText(R.id.hypertension_sce_tureclass, new String[] {
				"控制满意", "控制不满意", "不良反应", "并发症" }, null);
		setChoiceEditText(R.id.hypertension_sce_mentaladjust, new String[] {
				"良好", "一般", "差", }, null);
		setChoiceEditText(R.id.hypertension_sce_obey, new String[] { "良好",
				"一般", "差", }, null);
		setChoiceEditText(R.id.hypertension_et_bingfazhengjiazhong,
				new String[] { "是", "否" }, null);
		setChoiceEditText(R.id.hypertension_scedt_drugreaction, new String[] {
				"无", "有" }, null);
		setChoiceEditText(R.id.hypertension_et_sce_salt, new String[] { "轻",
				"中", "重" }, null);
		setChoiceEditText(R.id.hypertension_et_sce_targesalt, new String[] {
				"轻", "中", "重" }, null);
		setChoiceEditText(R.id.hypertension_symps, getResources()
				.getStringArray(R.array.select_hypertensionsymptom), "其他");
		setChoiceEditText(R.id.hypertension_turemethod, new String[] { "门诊",
				"家庭", "电话", "短信", "网络", "其他" }, null);
		setChoiceEditText(R.id.hypertension_sce_drugobey, new String[] { "规律",
				"间断", "不服药" }, null);
		setChoiceEditText(R.id.hypertension_zhuangui, new String[] { "继续随访",
				"暂时失访", "终止管理" }, null);
		setChoiceEditText(R.id.hypertension_et_yinshi, new String[] { "规律",
				"不规律" }, null);
		setChoiceEditText(R.id.hypertension_et_riskiness, new String[] { "无",
				"男性＞55岁或女性＞65岁", "吸烟", "血脂异常", "早发心血管疾病家族史", "腹型肥胖或肥胖",
				"缺乏体力活动", "高敏C反应蛋白≥3mg/L或C反应蛋白≥10mg/L", "血压异常" }, null);
		setChoiceEditText(R.id.hypertension_et_weixian, new String[] { "低危",
				"中危", "高危", "很高危" }, null);
		setChoiceEditText(R.id.hypertension_edt_loseWeight, new String[] {
				"不需要", "需要" }, null);
		setChoiceEditText(R.id.hypertension_edt_targedrinkingtype,
				new String[] { "白酒(≥42度)", "白酒(＜42度)", "啤酒", "黄酒、米酒", "葡萄酒",
						"其他", "不饮酒" }, null);
		// 并发症
		setChoiceEditText(R.id.hypertension_et_bingfazheng, new String[] { "无",
				"缺血性卒中", "脑出血", "短暂性脑缺血发作", "心肌梗死史", "冠状动脉血运重建", "心绞痛",
				"充血性心力衰竭", "糖尿病肾病", "肾功能受损（血清肌酐）", "视网膜病变" }, null);
	}
}
